<!-- 我们的月份查询 -->

<template>
  <WebSearch>
    <template #btn>
      <ParamSelect
        v-if="param.hasType"
        bind="type"
        :dict="DICT.TYPE"
        :autoSearch="false"
        noClear
        @change="changeType"
      />
      <BtnDownload @click="toExport" />
    </template>

    <ParamSelect v-if="selectLabel" :label="selectLabel" :bind="selectBind" :dict="selectDict" />

    <ParamMonth bind="startTime" history noClear />
  </WebSearch>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import OurSearchDate from '../OurSearchDate'

// ============================== 导出组件 ============================== //

export default CORE.extend(OurSearchDate, {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'OurSearchMonth',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [...OurSearchDate.mixins, CORE.mixInfo()],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    ...OurSearchDate.computed,

    /**
     * 文件名称
     */
    fileName() {
      const { param, filePre, selectLabel, selectBind, selectDict } = this
      const all = `${CORE.MAP.ALL}${selectLabel}`
      const selectStr = selectLabel ? ` [${CORE.dict(selectDict, param[selectBind]) || all}]` : ''
      const start = CORE.dateStr(param.startTime).slice(0, 7)
      return `${filePre}${selectStr} [${start}]`
    },
  },

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听月份选择
     */
    'param.startTime': {
      immediate: true,
      handler() {
        this.changeMonth()
      },
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    ...OurSearchDate.methods,

    /**
     * 切换月份
     */
    changeMonth() {
      const { param } = this
      param.endTime = CORE.timeNum(param.startTime, 0, 0, 1) - 1000

      this.startInfo()
    },
  },
})
</script>
